<template>
  <div>
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane
        v-for="(item,index) of activeItemList"
        :key="index"
        :label="item.pc_menu_name"
        :name="item.id"
      >
      <el-button v-if="currentindex==2" type="success" style="float: right;margin-right: 150px;" @click="addgrop">添加</el-button>
        <el-table border v-if="item.id==116" :data="tableData" style="width: 100%">
          <el-table-column prop="store_name" label="店名"></el-table-column>
          <el-table-column prop="address" label="地址"></el-table-column>
          <el-table-column prop="open_shop_uuid" label="绑定"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="text" v-if="showbtnedit" @click="handleEdit(scope.row)">修改绑定</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div style="width:100%;text-align:center;margin:50px auto;" v-if="item.id==116">
          <el-pagination
            background
            :page-sizes="[10, 20, 50, 100]"
            :page-size="10"
            layout="total,prev, sizes, pager, next, jumper"
            :total="totle"
            @size-change="handleSizeChange"
            @current-change="fenyeBtn"
          ></el-pagination>
        </div>
        <el-table border v-if="item.id==117" :data="tableDatas" style="width: 100%">
          <el-table-column prop="add_time" label="验券时间"></el-table-column>
          <el-table-column prop="code" label="券码"></el-table-column>
          <el-table-column prop="coupon_name" label="点评套餐"></el-table-column>
          <el-table-column prop="phone" label="点评手机"></el-table-column>
          <el-table-column prop="store_name" label="兑换门店"></el-table-column>
          <el-table-column prop="set_name" label="兑换标的"></el-table-column>
          <el-table-column prop="nickname" label="兑换人">
            <template slot-scope="scope">
              <div style="display:flex;align-items:center">
                <img
                  :src="scope.row.wechat_avatar"
                  :fit="fit"
                  style="width:28px;height:28px;border-radius:4px;display:inline-block"
                  alt
                />
                <div style="margin-left:10px">{{scope.row.nickname}}</div>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <div style="width:100%;text-align:center;margin:50px auto;" v-if="item.id==117">
          <el-pagination
            background
            :page-sizes="[10, 20, 50, 100]"
            :page-size="10"
            layout="total,prev, sizes, pager, next, jumper"
            :total="totles"
            @size-change="handleSizeChanges"
            @current-change="fenyeBtns"
          ></el-pagination>
        </div>
        <el-table border v-if="item.id==159" :data="tableData2" style="width: 100%">
          <el-table-column prop="name" label="团购名称"></el-table-column>
          <el-table-column prop="dealgroup_id" label="团购号"></el-table-column>
          <el-table-column prop="store_name" label="门店名称"></el-table-column>
          <el-table-column prop="type" label="类型">
             <template slot-scope="scope">
                <span v-if="scope.row.type==1">座位</span>
                <span v-if="scope.row.type==2">会议室</span>
              </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="text" @click="handEdit(scope.row)">编辑</el-button>
              <el-button type="text" @click="handdel(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div style="width:100%;text-align:center;margin:50px auto;" v-if="item.id==159">
          <el-pagination
            background
            :page-sizes="[10, 20, 50, 100]"
            :page-size="10"
            layout="total,prev, sizes, pager, next, jumper"
            :total="totle2"
            @size-change="handleSizeChange2"
            @current-change="fenyeBtn2"
          ></el-pagination>
        </div>
      </el-tab-pane>
      <!-- <el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>
      <el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>
      <el-tab-pane label="定时任务补偿" name="fourth">定时任务补偿</el-tab-pane>-->
    </el-tabs>
    <el-dialog title="修改绑定" :visible.sync="editpopup" width="50%" @close="closeDialog()">
      <el-form
        ref="formInfo"
        :model="formInfo"
        class="demo-form-inline"
        :rules="rules"
        label-width="100px"
      >
        <el-form-item label="门店" prop="store_name">
          <span>{{formInfo.store_name}}</span>
        </el-form-item>
        <el-form-item label="美团门店ID">
          <el-input placeholder v-model="formInfo.open_shop_uuid" style="width:50%"></el-input>
        </el-form-item>
        <el-form-item label="美团类型">
           <el-select v-model="values" style="width:50%" placeholder="请选择">
            <el-option
              v-for="item in voldata"
              :key="item.id"
              :label="item.id"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item style="text-align: right;">
          <el-button @click="editpopup=false">取消</el-button>
          <el-button type="primary" @click="submitForm('formInfo')">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="添加美团套餐" :visible.sync="addgroppopup" width="50%" @close="closeaddDialog('addformInfo')">
      <el-form
        ref="addformInfo"
        :model="addformInfo"
        class="demo-form-inline"
        :rules="rules"
        label-width="100px"
      >
        <el-form-item label="团购名称" prop="name">
          <el-input v-model="addformInfo.name"></el-input>
        </el-form-item>
        <el-form-item label="团购号" prop="dealgroup_id">
          <el-input v-model="addformInfo.dealgroup_id" @input="v => addformInfo.dealgroup_id = v.replace(/[^\d]/g,'')" minlength=1 maxlength=10 style="width:50%"></el-input>
        </el-form-item>
        <el-form-item label="门店" prop="shop">
          <el-select v-model="addformInfo.shop" multiple @change="changestore" style="width:50%" clearable placeholder="请选择">
            <el-option
              v-for="item in options1"
              :key="item.id"
              :label="item.store_name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="类型" prop="type">
           <el-select v-model="addformInfo.type" @change="changetype" style="width:50%" placeholder="请选择">
            <el-option
              v-for="item in groptype"
              :key="item.id"
              :label="item.text"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
         <el-form-item v-if="type2" label="会议室最高人数" prop="roomnum">
          <el-input v-model="addformInfo.roomnum"></el-input>
        </el-form-item>
        <el-form-item v-if="type1" label="套餐" prop="meal">
          <el-select v-model="addformInfo.meal" @change="buymealchage($event)" style="width:50%" placeholder="请选择">
            <el-option
              v-for="item in meallists"
              :key="item.id"
              :label="item.title"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <div v-if="isdaynum">
           <el-radio-group v-model="radio1" @change="radiochang">
          <div class="flexwap" v-for="(item,index) in daynumlist" :key="index">
          <el-form-item label="天数">
            <el-input disabled v-model="item.day">
              <template slot="append">天</template>
            </el-input>
          </el-form-item>
          <el-form-item label="价格">
            <el-input disabled v-model="item.price">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
           <el-radio style="margin-left:20px" :label="item.id" border>选择此套餐</el-radio>
        </div>
          </el-radio-group>
        </div>
        <el-form-item v-if="typeid==2" label="有效期天数" prop="dates">
          <el-input v-model="addformInfo.dates" oninput="value=value.replace(/[^\d]/g,'')"></el-input>
        </el-form-item>
        <el-form-item v-if="typeid==2" label="小时数" prop="hour">
          <el-input v-model="addformInfo.hour" oninput="value=value.replace(/[^\d]/g,'')"></el-input>
        </el-form-item>
        <el-form-item style="text-align: right;">
          <el-button @click="closeaddDialog('addformInfo')">取消</el-button>
          <el-button type="primary" @click="submitFormadd('addformInfo')">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="编辑美团套餐" :visible.sync="editgroppopup" width="50%" @close="closeeditDialog()">
      <el-form
        ref="editformInfo"
        :model="editformInfo"
        class="demo-form-inline"
        :rules="rulesd"
        label-width="100px"
      >
        <el-form-item label="团购名称" prop="name">
          <el-input v-model="editformInfo.name"></el-input>
        </el-form-item>
        <el-form-item label="团购号" prop="dealgroup_id">
          <el-input v-model="editformInfo.dealgroup_id" @input="v => editformInfo.dealgroup_id = v.replace(/[^\d]/g,'')" minlength=1 maxlength=10 style="width:50%"></el-input>
        </el-form-item>
        <el-form-item label="门店" prop="store_id">
          <el-select :disabled="true" v-model="editformInfo.store_id" @change="$forceUpdate()" multiple style="width:50%" clearable placeholder="请选择">
            <el-option
              v-for="item in options1"
              :key="item.id"
              :label="item.store_name"
              :value="String(item.id)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="类型" prop="type">
           <el-select :disabled="true" v-model="editformInfo.type" style="width:50%" placeholder="请选择">
            <el-option
              v-for="item in groptype"
              :key="item.id"
              :label="item.text"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
         <el-form-item v-if="editformInfo.type==2" label="会议室最高人数" prop="room_num">
          <el-input v-model="editformInfo.room_num"></el-input>
        </el-form-item>
        <el-form-item v-if="editformInfo.type==1" label="套餐" prop="set_id">
          <el-select v-model="editformInfo.set_id" @change="editmealchage($event)" style="width:50%" clearable placeholder="请选择">
            <el-option
              v-for="item in meallists"
              :key="item.id"
              :label="item.title"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <div v-if="isdaynum">
           <el-radio-group v-model="radio1" @change="radiochangs">
          <div class="flexwap" v-for="(item,index) in daynumlist" :key="index">
          <el-form-item label="天数">
            <el-input disabled v-model="item.day">
              <template slot="append">天</template>
            </el-input>
          </el-form-item>
          <el-form-item label="价格">
            <el-input disabled v-model="item.price">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
           <el-radio style="margin-left:20px" :label="item.id" border>选择此套餐</el-radio>
        </div>
          </el-radio-group>
        </div>
        <el-form-item v-if="editformInfo.type==2" label="有效期天数" prop="indate">
          <el-input v-model="editformInfo.indate" oninput="value=value.replace(/[^\d]/g,'')"></el-input>
        </el-form-item>
        <el-form-item v-if="editformInfo.type==2" label="小时数" prop="hour">
          <el-input v-model="editformInfo.hour" oninput="value=value.replace(/[^\d]/g,'')"></el-input>
        </el-form-item>
        <el-form-item style="text-align: right;">
          <el-button @click="editgroppopup=false;isdaynum=false">取消</el-button>
          <el-button type="primary" @click="submitFormedit('editformInfo')">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { lists, store, volksw, oreList, unbind, Meituanlist,Meituandelete,Meituanadd,Meituanedit,setList,isCoupon } from "@/api/user";
import { adminStore } from "@/api/menu";
import Base64 from "@/utils/base";
import { getp_id } from "@/utils/getmenuid";
export default {
  data() {
    return {
      rules:{
        name: [
          { required: true, message: "请输入团购名称", trigger: "change" }
        ],
        dealgroup_id:[
          { required: true, message: "请输入团购ID", trigger: "change" }
        ],
        type:[
          { required: true, message: "请选择类型", trigger: "change" }
        ],
        shop:[
          { required: true, message: "请选择门店", trigger: "blur" }
        ],
        dates:[
          { required: true, message: "请输入有效期天数", trigger: "change" }
        ],
        meal:[
          { required: true, message: "请选择套餐", trigger: "change" }
        ],
        roomnum:[
          { required: true, message: "请输入会议室最高人数", trigger: "change" }
        ]
      },
      rulesd:{
         name: [
          { required: true, message: "请输入团购名称", trigger: "change" }
        ],
        dealgroup_id:[
          { required: true, message: "请输入团购ID", trigger: "change" }
        ],
        type:[
          { required: true, message: "请选择类型", trigger: "change" }
        ],
        store_id:[
          { required: true, message: "请选择门店", trigger: "blur" }
        ],
        indate:[
          { required: true, message: "请输入有效期天数", trigger: "change" }
        ],
        set_id:[
          { required: true, message: "请选择套餐", trigger: "change" }
        ],
        room_num:[
          { required: true, message: "请输入会议室最高人数", trigger: "change" }
        ]
      },
      currentindex:0,
      value: "",
      activeName: "",
      tableData: "",
      tableDatas: "",
      tableData2: "",
      editpopup: false,
      formInfo: "",
      id: "",
      addformInfo:{
        name:"",
        dealgroup_id:"",
        type:"",
        shop:"",
        dates:"",
        roomnum:"",
        meal:"",
        hour:""
      },
      options1: "",
      editformInfo:"",
      system_30: false,
      system_31: false,
      system_39: false,
      tabs: "",
      showbtnedit: true,
      page:1,
      pages:1,
      page2:1,
      totle:10,
      totles:10,
      totle2:10,
      num:10,
      nums:10,
      num2:10,
      values:"",
      addgroppopup:false,
      editgroppopup:false,
      meallists:"",
      groptype:[
        {
          id:1,
          text:'座位'
        },
        {
          id:2,
          text:'会议室'
        },
      ],
      voldata:[
        {
          id:1
        },
        {
          id:2
        }
      ],
      editid:"",
      type1:false,
      type2:false,
      storeid:"",
      radio1:"",
      typeid:"",
      mealid:"",
      daynumlist:"",
      isdaynum: false,
      // cardday:"",
      // cardprice:"",
    }
  },
  created() {
    this.getadminstore();
    this.getlists();
    setTimeout(() => {
      this.storelist();
      this.getstoreList()
    }, 500);
  },
  computed: {
    activeItemList() {
      return this.tabs.filter(item => {
        return item.id != 136;
      });
    }
  },
  methods: {
     getadminstore() {
      adminStore({
        request_data: Base64.encode(
          JSON.stringify({
            store_id: JSON.parse(localStorage.getItem("storemenu"))[0].id||"",
            p_id: getp_id()
          })
        )
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.options1 = res.data
      });
    },
    //美团列表编辑
    handEdit(data){
      this.editid = data.id
      this.editgroppopup = true
      this.editformInfo = JSON.parse(JSON.stringify(data))
      this.editformInfo.store_id = data.store_id.split(',')
      if(data.type==1){
        setList({
        request_data: Base64.encode(
          JSON.stringify({
            store_id:data.store_id
          })
        )
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.meallists = res.result;
        this.getMeals(data)
      })
      }
    },
    getMeals(data){
      let obj = {};
      this.radio1 = ""
      obj = this.meallists.find(item => {
        //model就是上面的数据源
        return item.id == data.set_id; //筛选出匹配数据
      })
      // this.typeid = obj.type
      this.mealid = obj.type
      if (obj.type == 1) {
        this.isdaynum = true;
        this.daynumlist = obj.set
        obj.set.map(v=>{
          if(v.day==data.indate){
            this.radio1 = v.id
            this.editformInfo.indate = v.day
          }
        })
      } 
      if(obj.type == 2){
        this.isdaynum = false;
        this.editformInfo.indate = obj.day
      }
      if(obj.type == 3) {
        this.isdaynum = false;
        this.editformInfo.indate = obj.day
      }
    },
    //美团列表删除
    handdel(data){
      this.$confirm("确定删除此条数据吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          Meituandelete({
            request_data: Base64.encode(JSON.stringify({ coupon_id: data.coupon_id }))
          }).then(res => {
            if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.getMeituanlist();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    // 关闭弹框
    closeDialog() {
      this.$refs["formInfo"].resetFields();
      this.editpopup = false;
    },
    closeaddDialog(addformInfo) {
      this.addgroppopup = false;
      this.isdaynum = false
      this.$refs[addformInfo].resetFields();
    },
    closeeditDialog() {
      this.isdaynum = false
      this.editgroppopup = false;
    },
    handleSizeChange(val) {
      this.num = val;
      this.storelist(this.page, this.num);
    },
     fenyeBtn(e) {
      this.page = e
      this.storelist(this.page,this.num);
    },
    handleSizeChanges(val) {
      this.nums = val;
      this.getvolkswlist(this.pages, this.nums);
    },
     fenyeBtns(e) {
      this.pages = e;
      this.getvolkswlist(this.pages,this.nums);
    },
    handleSizeChange2(val) {
      this.num2 = val;
      this.getMeituanlist(this.page2, this.num2);
    },
     fenyeBtn2(e) {
      this.page2 = e;
      this.getMeituanlist(this.page2,this.num2);
    },
    //切换类型
    changetype(e){
      this.typeid = e
      if(e==2){
        this.type2 = true
        this.type1 = false
        this.isdaynum = false
        this.addformInfo.meal = ""
        this.addformInfo.dates = ""
        this.addformInfo.hour = ""
      }
      if(e==1){
        this.type2 = false
        this.type1 = true
        this.addformInfo.meal = ""
        this.addformInfo.dates = ""
        // this.isdaynum = true
      }
    },
    //选择套餐
    buymealchage(event){
      let obj = {};
      this.radio1 = ""
      obj = this.meallists.find(item => {
        //model就是上面的数据源
        return item.id === event; //筛选出匹配数据
      })
      // this.typeid = obj.type
      this.mealid = obj.type
      if (obj.type == 1) {
        this.isdaynum = true;
        this.daynumlist = obj.set
        this.addformInfo.dates = ""
      } 
      if(obj.type == 2) {
        this.isdaynum = false;
        this.addformInfo.dates = obj.day
      }
      if(obj.type == 3){
        this.isdaynum = false;
        this.addformInfo.dates = obj.day
      }
    },
    editmealchage(event){
      let obj = {};
      console.log(event)
      console.log(this.meallists)
      this.radio1 = ""
      obj = this.meallists.find(item => {
        //model就是上面的数据源
        return item.id == event; //筛选出匹配数据
      })
      // this.typeid = obj.type
      this.mealid = obj.type
      if (obj.type == 1) {
        this.isdaynum = true;
        this.daynumlist = obj.set
        this.editformInfo.indate = ""
      } 
      if(obj.type == 2){
        this.isdaynum = false;
        this.editformInfo.indate = obj.day
      }
      if(obj.type == 3) {
        this.isdaynum = false;
        this.editformInfo.indate = obj.day
      }
    },
     radiochang(e){
      this.radio1 = e
     this.daynumlist.map(item => {
        //model就是上面的数据源
        if(item.id == e){
          this.addformInfo.dates = item.day
          // this.cardprice = item.price
        }
      });
    },
    radiochangs(e){
      console.log(e)
     this.radio1 = e
     this.daynumlist.map(item => {
        //model就是上面的数据源
        if(item.id == e){
          this.editformInfo.indate = item.day
          // this.cardprice = item.price
        }
      });
    },
    //切换门店
    changestore(e){
      // console.log(e)
      // return
      // this.storeid = e
      this.isdaynum = false
      this.radio1 = ""
      setList({
        request_data: Base64.encode(
          JSON.stringify({
            store_id:e.join(',')
          })
        )
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.meallists = res.result;
      })
    },
    //
    submitForm() {
      if(this.values==""){
        this.$message({
            message:"请选择美团类型",
            type:"info"
          })
          return
      }
      unbind({
        request_data: Base64.encode(
          JSON.stringify({
            store_id: this.id,
            open_shop_uuid: this.formInfo.open_shop_uuid,
            meituan_type:this.values
          })
        )
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.editpopup = false;
        this.storelist()
      });
    },
    iscoupon(){
      let parmes = {
        dealgroup_id:this.addformInfo.dealgroup_id
      }
      isCoupon({
          request_data: Base64.encode(JSON.stringify(parmes))
        }).then(res => {
          if(res.status==2){
            this.$message({
              message:res.message,
              type:'warning'
            })
            return
          }
          if(res.result=='1'){
            return "1"
          }
          if(res.result=='2'){
            return "2"
          }
        })
    },
    iseditcoupon(){
      let parmes = {
        dealgroup_id:this.editformInfo.dealgroup_id
      }
      isCoupon({
          request_data: Base64.encode(JSON.stringify(parmes))
        }).then(res => {
          if(res.status==2){
            this.$message({
              message:res.message,
              type:'warning'
            })
            return
          }
          if(res.result=='1'){
            return "1"
          }
          if(res.result=='2'){
            return "2"
          }
        })
    },
    //添加美团套餐
    submitFormadd(addformInfo){
      this.$refs[addformInfo].validate(valid => {
      if (valid) { 
        if(this.typeid==2){
          var parmesadd = {
          store_id:this.addformInfo.shop.join(','),
          name:this.addformInfo.name,
          dealgroup_id:this.addformInfo.dealgroup_id,
          type:this.addformInfo.type,
          indate:this.addformInfo.dates,
          room_num:this.addformInfo.roomnum,
          hour:this.addformInfo.hour,
        }
        }
        if(this.typeid==1){
           if(this.radio1==""&&this.mealid==1){
              this.$message({
                  message:"请选择套餐",
                  type:'warning'
              })
              return
            }
          var parmesadd = {
          store_id:this.addformInfo.shop.join(','),
          name:this.addformInfo.name,
          dealgroup_id:this.addformInfo.dealgroup_id,
          type:this.addformInfo.type,
          indate:this.addformInfo.dates,
          set_id:this.addformInfo.meal
        }
        }
        if(this.addformInfo.dates=="0"){
          this.$message({
                  message:"有效期天数需大于0",
                  type:'warning'
              })
              return
        }
      if(this.iscoupon()=='1'){
        Meituanadd({
          request_data: Base64.encode(JSON.stringify(parmesadd))
        }).then(res => {
          if(res.status==2){
            this.$message({
              message:res.message,
              type:'warning'
            })
            return
          }
          this.isdaynum = false
          this.addgroppopup = false
          this.$refs[addformInfo].resetFields()
          this.$message({
              message:res.message,
              type:'success'
          })
          this.getMeituanlist()
        })
      }else{
          this.$confirm("已存在此美团套餐，是否再次添加?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          Meituanadd({
          request_data: Base64.encode(JSON.stringify(parmesadd))
        }).then(res => {
          if(res.status==2){
            this.$message({
              message:res.message,
              type:'warning'
            })
            return
          }
          this.isdaynum = false
          this.addgroppopup = false
          this.$refs[addformInfo].resetFields()
          this.$message({
              message:res.message,
              type:'success'
          })
          this.getMeituanlist()
        })
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
      }
        } else {
         
        }
    })
    },
    //编辑美团套餐
    submitFormedit(editformInfo){
      // console.log(this.editformInfo)
      // console.log(this.radio1)
      // console.log(this.mealid)
  this.$refs[editformInfo].validate(valid => {
        if (valid) {
        if(this.editformInfo.type==2){
          var editparmesadd = {
          store_id:this.editformInfo.store_id,
          name:this.editformInfo.name,
          coupon_id:this.editformInfo.coupon_id,
          dealgroup_id:this.editformInfo.dealgroup_id,
          type:this.editformInfo.type,
          indate:this.editformInfo.indate,
          room_num:this.editformInfo.room_num,
          hour:this.editformInfo.hour,
        }
        }
        if(this.editformInfo.type==1){
           if(this.radio1==""&&this.mealid==1){
              this.$message({
                  message:"请选择套餐",
                  type:'warning'
              })
              return
            }
          var editparmesadd = {
          store_id:this.editformInfo.store_id,
          name:this.editformInfo.name,
          coupon_id:this.editformInfo.coupon_id,
          dealgroup_id:this.editformInfo.dealgroup_id,
          type:this.editformInfo.type,
          indate:this.editformInfo.indate,
          set_id:this.editformInfo.set_id
        }
        }
        if(this.editformInfo.indate=="0"){
          this.$message({
                  message:"有效期天数需大于0",
                  type:'warning'
              })
              return
        }
        if(this.iseditcoupon()=='1'){
          Meituanedit({
          request_data: Base64.encode(JSON.stringify(editparmesadd))
        }).then(res => {
          if(res.status==2){
            this.$message({
              message:res.message,
              type:'warning'
            })
            return
          }
          this.isdaynum = false
          this.editgroppopup = false
          this.$message({
              message:res.message,
              type:'success'
          })
          this.getMeituanlist(this.page2,this.num2)
        })
        }else{
          this.$confirm("已存在此美团套餐，是否修改?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          Meituanedit({
          request_data: Base64.encode(JSON.stringify(editparmesadd))
        }).then(res => {
          if(res.status==2){
            this.$message({
              message:res.message,
              type:'warning'
            })
            return
          }
          this.isdaynum = false
          this.editgroppopup = false
          this.$message({
              message:res.message,
              type:'success'
          })
          this.getMeituanlist(this.page2,this.num2)
        })
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
        }
        
        } else {
         
        }
    })
    },
    getstoreList() {
      adminStore({
        request_data: Base64.encode(JSON.stringify({ store_id: "" }))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.options = res.data;
      });
    },
    handleClick(tab, event) {
      this.currentindex = tab.index
      if (tab.index == 0) {
        this.storelist();
      }
      if (tab.index == 1) {
        this.getvolkswlist();
      }
      if(tab.index == 2){
        this.getMeituanlist()
      }
    },
    getMeituanlist(page,num){
     let parmes = {
        page: page || this.page2,
        limit: num || this.num2
      };
      Meituanlist({
        request_data: Base64.encode(JSON.stringify(parmes))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.tableData2 = res.result.data;
        this.totle2 = res.result.total;
      });
    },
    //添加美团套餐
    addgrop(){
      this.addgroppopup = true
    },
    handleEdit(val) {
      this.editpopup = true;
      this.id = val.id;
      this.formInfo = JSON.parse(JSON.stringify(val));
      // this.getstoreList();
    },
    storelist(page, num) {
      let parmes = {
        page: page || this.page,
        limit: num || this.num
      };
      store({
        request_data: Base64.encode(JSON.stringify(parmes))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.tableData = res.result.data;
        this.totle = res.result.count;
      });
    },
    getvolkswlist(page, num) {
      let parmes = {
        page: page || this.pages,
        limit: num || this.nums
      };
      volksw({
        request_data: Base64.encode(JSON.stringify(parmes))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.tableDatas = res.result.data;
        this.totles = res.result.total;
      });
    },
    getlists() {
      lists({
        request_data: Base64.encode(JSON.stringify({ pid: getp_id() }))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.activeName = res.result[0].id;
        this.tabs = res.result;
        // let btnarr = [];
        // res.result.map(v => {
        //   btnarr.push(v.class_mark);
        // });
        // btnarr.forEach(item => {
        //   if (item == "system_30") {
        //     this.system_30 = true;
        //   }
        //   if (item == "system_31") {
        //     this.system_31 = true;
        //   }
        //   if(item == "system_39"){
        //     this.system_39 = true;
        //   }
        // });
      });
    }
  }
};
</script>
<style scoped>
.el-tabs__nav-scroll {
  background: #f4f5f8;
}
::v-deep .el-tabs__header{
  margin-bottom: 0 !important;
}
.flexwap {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
}
</style>
